<?php
/**
 * Created by PhpStorm.
 * User: zhouxin
 * Date: 2018/9/29
 * Time: 20:47
 */


include 'config.php';
if($_SERVER["REQUEST_METHOD"]=="POST")
{
    session_start();//开启session
    if(isset($_REQUEST["telphone"])&&isset($_REQUEST["upwd"]))
    {
        $sqllogin = "SELECT * FROM userinfo WHERE user_telphone='" . $_REQUEST["telphone"] . "' AND user_pwd='" . $_REQUEST["upwd"] . "';";
        //4. 执行sql语句
        $result = $conn->query($sqllogin);

        if($result->num_rows>=1)
        {
            //登陆成功
            $_SESSION["userinfo"]=$result->fetch_assoc();
            foreach($_SESSION["userinfo"] as $key=>$value)
            {
                if($key=="user_id")
                    $user_id=$value;
            }

            print_r(json_encode(array("status"=>1,"msg"=>"登录成功","user_id"=>$user_id)));

        }
        else{
            //用户名或密码错误
            print_r(json_encode(array("status"=>-1,"msg"=>"用户名或密码错误")));
        }
    }
    else{
        //用户名密码不能为空
        print_r(json_encode(array("status"=>-2,"msg"=>"用户名密码不能为空")));
    }
}
else{
    //不支持的请求方式
    print_r(json_encode(array("status"=>0,"msg"=>"不支持的请求方式")));
}